<?php

namespace frontend\controllers;

use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use frontend\models\UserInfo;
use frontend\models\SendSms;

class RegistrationController extends Controller
{
    public function actionSendToken()
    {
    	if($tel=yii::$app->request->post('tel'))
    	{
    	    $model=UserInfo::getIdByUsername($tel);
    	    if(!empty($model))
    	    {
    	        echo "该手机号已注册";
    	    }
    	    else
    	    {
    	        $sms=new SendSms();
    	        if($sms->send($tel))
    	        {
    	            echo "验证码已发送";
    	        }
    	        else 
    	        {
    	            echo "验证码发送失败，请重试。";
    	        }
    	    }
    	}
    	else
    	{
    		return Yii::t('app', 'that is wrong tel');
    	}
    }
    public function actionResetPasswordSendToken()
    {
        if(yii::$app->request->isAjax&&yii::$app->request->post('value'))
        {
            $value=yii::$app->request->post('value');
            $num=mt_rand(100000,999999);
            //$num = 123456;
            Yii::$app->session['verify_code']=$num;
            $str="您正在修改JAJAHOME登录密码，您的验证码为：".Yii::$app->session['verify_code']."，请勿告诉他人。";
            $model=UserInfo::getIdByUsername($value);
            if(empty($model))
            {
                echo "无此手机号";
            }
            else 
            {
                $sms=new SendSms();
                if($sms->send_mobile_SMS($value,$str))
                {
                    echo "短信验证码已发送";
                }
                else
                {
                    echo "验证码发送失败，请重试。";
                }
            }
        }
    }
}
